<template>
	<view>
		<u-loading-page :loading="loadding" loading-mode="semicircle" loading-text="Hello Pro"></u-loading-page>
		<view v-if="!loadding">
			<view class="policy_box" v-if="data !== undefined && data!== null && data.length>0">
				<view class="policy_list" v-for="(item,index) in data" :key="index">
					<text @click="info(item.id)">{{item.title}}</text>
					<!-- <text @click="_delete(item.id)">删除</text> -->
					<u-icon name="trash" size="22" color="#fa3534" @click="_delete(item.id)"></u-icon>
				</view>
			</view>
			<u-empty class="policy_box" v-else mode="list" icon="/static/Empty/data_null.png">
			</u-empty>
			<view class="confirm" @click="new_add">
				<u--text prefixIcon="plus" iconStyle="font-size: 38rpx; color: #ffffff; margin-right: 10rpx;"
					color="#ffffff" align="center" text="新增"></u--text>
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				loadding: true,
				data: [],
				product_id: null
			}
		},
		onLoad(e) {
			this.product_id = e.id
		},
		onShow() {
			this._request(this.product_id)
		},
		methods: {
			//删除
			_delete(id) {
				let _this = this
				uni.showModal({
					title: '提示',
					content: '是否删除',
					success: function(res) {
						if (res.confirm) {
							_this.delete_qr(id)
						}
					}
				});
			},
			async delete_qr(id) {
				uni.showLoading({
					title: '加载中'
				});
				const userinfo = uni.getStorageSync('userinfo');
				const {
					data: res
				} = await this.$myHttp5({
					url: 'setting/deletePolicy',
					data: {
						id: id
					},
					header: {
						'token': userinfo.token
					},
				});
				let _this = this
				if (res.code == 1) {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 1500,
						success() {
							setTimeout(() => {
								_this.$router.go(0)
							}, 500)
						}
					})
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 3000
					})
				}
			},
			async _request(id) {
				const userinfo = uni.getStorageSync('userinfo');
				const {
					data: res
				} = await this.$myHttp5({
					url: 'Setting/getMyAgencyPolicy',
					data: {
						product_id: id
					},
					header: {
						'token': userinfo.token
					},
				});
				this.loadding = false
				if (res.code == 1) {
					this.data = res.data
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 3000
					})
				}
			},
			info(id) {
				uni.navigateTo({
					url: '/pages/version5/mine/policy/detail?id=' + id + '&type=2'
				})
			},
			// 新增按钮
			new_add() {
				uni.navigateTo({
					url: '/pages/version5/index/SetPolicy/new_add?product_id=' + this.product_id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.policy_box {
		padding: 30rpx;
		box-sizing: border-box;
		height: 80vh;
		overflow-y: auto;

		.policy_list {
			padding: 20rpx;
			border-radius: 15rpx;
			box-shadow: 0px 1px 14px -10px #999;
			margin-bottom: 30rpx;
			display: flex;
			justify-content: space-between;

			text {
				display: flex;
				justify-content: center;
			}
		}
	}

	.confirm {
		position: fixed;
		left: 50%;
		bottom: 30rpx;
		transform: translate(-50%, -50%);
		background-color: #018afe;
		width: 95%;
		border-radius: 15rpx;
		font-size: 28rpx;
		padding: 20rpx;
		box-sizing: border-box;
		color: #fff;
		text-align: center;
		transition: all 0.5s;
	}
</style>